from django.db import migrations


def copy_fk_to_m2m(apps, schema_editor):
    WRA = apps.get_model('deal', 'WinningResultAnnouncement')
    for w in WRA.objects.all():
        try:
            if getattr(w, 'winning_company_id', None):
                w.winning_companies.add(w.winning_company_id)
        except Exception:
            pass


def noop_reverse(apps, schema_editor):
    pass


class Migration(migrations.Migration):
    dependencies = [
        ('deal', '0008_winningresultannouncement_winning_companies'),
    ]

    operations = [
        migrations.RunPython(copy_fk_to_m2m, noop_reverse),
    ]